#region Developer's comment header
/* Documenti.cs
 * 
 * author:    DS2171
 * copyright: DS2171
 * 
 * history:   15/11/2010, DS2171: Created.
 *
 */
#endregion
#region Using directives

using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Xml.Serialization;

using Chili.Opf3;
using Chili.Opf3.Relations;


#endregion

namespace DocManagerORM.Entità
{
	/// <summary>
	/// Persistent object for the "Documenti" table.
	/// </summary>
	[Serializable]
	[Persistent("Documenti")]
	public partial class Documenti : IObjectNotification, ISelfContainingObject, INotifyPropertyChanged, IDocumenti
	{
		#region Fields

		private int _id;
		private int? _iDPadre;
		private string _titolo;
		private string _fileName;
		private Blob _documento = new Blob();
		private string _ext;
		private bool? _solaLettura;
		private int? _versione;
		private int _fk_IDCat;
		private int? _fk_IDSotCat;
		private int? _fk_IDTags;
		private Guid? _fk_RuoliModifica = Guid.NewGuid();
		private Guid? _fk_RuoliVedi = Guid.NewGuid();
		private string _tagsLiberi;
		private DateTime? _validoFinoAl;
		private DateTime? _dataInsert;

		#endregion

		#region Relations

		[Relation("Fk_RuoliModifica = RoleId", PersistRelationship = PersistRelationships.ChildFirst)]
		private ObjectHolder<aspnet_Roles> _aspnet_Roles = new ObjectHolder<aspnet_Roles>();

		/// <summary>
		/// Specifies the connected "aspnet_Roles" persistent object.
		/// </summary>
		[XmlIgnore]
		public aspnet_Roles aspnet_Roles
		{
			get { return _aspnet_Roles.InnerObject; }
			set { _aspnet_Roles.InnerObject = value; }
		}

		[Relation("Fk_IDCat = ID", PersistRelationship = PersistRelationships.ChildFirst)]
		private ObjectHolder<Categorie> _categorie = new ObjectHolder<Categorie>();

		/// <summary>
		/// Specifies the connected "Categorie" persistent object.
		/// </summary>
		[XmlIgnore]
		public Categorie Categorie
		{
			get { return _categorie.InnerObject; }
			set { _categorie.InnerObject = value; }
		}

		[Relation("Fk_IDSotCat = ID", PersistRelationship = PersistRelationships.ChildFirst)]
		private ObjectHolder<SottoCategorie> _sottoCategorie = new ObjectHolder<SottoCategorie>();

		/// <summary>
		/// Specifies the connected "SottoCategorie" persistent object.
		/// </summary>
		[XmlIgnore]
		public SottoCategorie SottoCategorie
		{
			get { return _sottoCategorie.InnerObject; }
			set { _sottoCategorie.InnerObject = value; }
		}

		[Relation("Fk_IDTags = ID", PersistRelationship = PersistRelationships.ChildFirst)]
		private ObjectHolder<Tags> _tags = new ObjectHolder<Tags>();

		/// <summary>
		/// Specifies the connected "Tags" persistent object.
		/// </summary>
		[XmlIgnore]
		public Tags Tags
		{
			get { return _tags.InnerObject; }
			set { _tags.InnerObject = value; }
		}

		[Relation("ID = Fk_IDDoc")]
		private ObjectSetHolder<Iters> _iters = new ObjectSetHolder<Iters>();

		/// <summary>
		/// Gets and sets a set of connected "Iters" persistent objects.
		/// </summary>
		[XmlIgnore]
		public ObjectSet<Iters> Iters
		{
			get { return _iters.InnerObject; }
		}

		#endregion

		#region Properties

		/// <summary>
		/// Returns the identifier of the persistent object. Don't set it manually!
		/// </summary>
		[Field("ID", AllowDBNull = false, Identifier = true, AutoNumber = true)]
		public int ID
		{
			get 
			{ 
				return _id; 
			}
			private set 
			{
				_id = value;

				OnRowChanged("ID");
			}
		}

		/// <summary>
		/// This property is mapped to the "IDPadre" field.  
		/// Storage comment: .
		/// </summary>
		[Field("IDPadre")]
		public int? IDPadre
		{
			get 
			{ 
				return _iDPadre; 
			}
			set 
			{
				_iDPadre = value;

				OnRowChanged("IDPadre");
			}
		}

		/// <summary>
		/// This property is mapped to the "Titolo" field. Length must be between 0 and 150 characters. 
		/// Storage comment: .
		/// </summary>
		[Field("Titolo")]
		public string Titolo
		{
			get 
			{ 
				return _titolo; 
			}
			set 
			{
				if (value != null && value.Length > 150)
					throw new ArgumentException("Value length must be between 0 and 150 characters.");

				_titolo = value;

				OnRowChanged("Titolo");
			}
		}

		/// <summary>
		/// This property is mapped to the "FileName" field. Length must be between 0 and 150 characters. Mandatory.
		/// Storage comment: .
		/// </summary>
		[Field("FileName", AllowDBNull = false)]
		public string FileName
		{
			get 
			{ 
				return _fileName; 
			}
			set 
			{
				if (value == null)
					throw new ArgumentNullException("value", "Value is null.");
				if (value != null && value.Length > 150)
					throw new ArgumentException("Value length must be between 0 and 150 characters.");

				_fileName = value;

				OnRowChanged("FileName");
			}
		}

		/// <summary>
		/// This property is mapped to the "Documento" field.  Mandatory.
		/// Storage comment: .
		/// </summary>
		[Field("Documento", AllowDBNull = false)]
		public Blob Documento
		{
			get 
			{ 
				return _documento; 
			}
			set 
			{
				_documento = value;

				OnRowChanged("Documento");
			}
		}

		/// <summary>
		/// This property is mapped to the "Ext" field. Length must be between 0 and 6 characters. Mandatory.
		/// Storage comment: .
		/// </summary>
		[Field("Ext", AllowDBNull = false)]
		public string Ext
		{
			get 
			{ 
				return _ext; 
			}
			set 
			{
				if (value == null)
					throw new ArgumentNullException("value", "Value is null.");
				if (value != null && value.Length > 6)
					throw new ArgumentException("Value length must be between 0 and 6 characters.");

				_ext = value;

				OnRowChanged("Ext");
			}
		}

		/// <summary>
		/// This property is mapped to the "SolaLettura" field.  
		/// Storage comment: .
		/// </summary>
		[Field("SolaLettura")]
		public bool? SolaLettura
		{
			get 
			{ 
				return _solaLettura; 
			}
			set 
			{
				_solaLettura = value;

				OnRowChanged("SolaLettura");
			}
		}

		/// <summary>
		/// This property is mapped to the "Versione" field.  
		/// Storage comment: .
		/// </summary>
		[Field("Versione")]
		public int? Versione
		{
			get 
			{ 
				return _versione; 
			}
			set 
			{
				_versione = value;

				OnRowChanged("Versione");
			}
		}

		/// <summary>
		/// The foreign key connected with another persistent object.
		/// </summary>
		[Field("Fk_IDCat", AllowDBNull = false)]
		public int Fk_IDCat
		{
			get 
			{ 
				return _fk_IDCat; 
			}
			private set 
			{
				_fk_IDCat = value;

				OnRowChanged("Fk_IDCat");
			}
		}

		/// <summary>
		/// The foreign key connected with another persistent object.
		/// </summary>
		[Field("Fk_IDSotCat")]
		public int? Fk_IDSotCat
		{
			get 
			{ 
				return _fk_IDSotCat; 
			}
			private set 
			{
				_fk_IDSotCat = value;

				OnRowChanged("Fk_IDSotCat");
			}
		}

		/// <summary>
		/// The foreign key connected with another persistent object.
		/// </summary>
		[Field("Fk_IDTags")]
		public int? Fk_IDTags
		{
			get 
			{ 
				return _fk_IDTags; 
			}
			private set 
			{
				_fk_IDTags = value;

				OnRowChanged("Fk_IDTags");
			}
		}

		/// <summary>
		/// The foreign key connected with another persistent object.
		/// </summary>
		[Field("Fk_RuoliModifica")]
		public Guid? Fk_RuoliModifica
		{
			get 
			{ 
				return _fk_RuoliModifica; 
			}
			private set 
			{
				_fk_RuoliModifica = value;

				OnRowChanged("Fk_RuoliModifica");
			}
		}

		/// <summary>
		/// This property is mapped to the "Fk_RuoliVedi" field.  
		/// Storage comment: .
		/// </summary>
		[Field("Fk_RuoliVedi")]
		public Guid? Fk_RuoliVedi
		{
			get 
			{ 
				return _fk_RuoliVedi; 
			}
			set 
			{
				_fk_RuoliVedi = value;

				OnRowChanged("Fk_RuoliVedi");
			}
		}

		/// <summary>
		/// This property is mapped to the "TagsLiberi" field. Length must be between 0 and 100 characters. 
		/// Storage comment: .
		/// </summary>
		[Field("TagsLiberi")]
		public string TagsLiberi
		{
			get 
			{ 
				return _tagsLiberi; 
			}
			set 
			{
				if (value != null && value.Length > 100)
					throw new ArgumentException("Value length must be between 0 and 100 characters.");

				_tagsLiberi = value;

				OnRowChanged("TagsLiberi");
			}
		}

		/// <summary>
		/// This property is mapped to the "ValidoFinoAl" field.  
		/// Storage comment: .
		/// </summary>
		[Field("ValidoFinoAl")]
		public DateTime? ValidoFinoAl
		{
			get 
			{ 
				return _validoFinoAl; 
			}
			set 
			{
				_validoFinoAl = value;

				OnRowChanged("ValidoFinoAl");
			}
		}

		/// <summary>
		/// This property is mapped to the "DataInsert" field.  
		/// Storage comment: .
		/// </summary>
		[Field("DataInsert")]
		public DateTime? DataInsert
		{
			get 
			{ 
				return _dataInsert; 
			}
			set 
			{
				_dataInsert = value;

				OnRowChanged("DataInsert");
			}
		}

		#endregion

		#region IObjectNotification Members

		/// <summary>
		/// Invoked by the framework before the persistent object is populated.
		/// </summary>
		/// <param name="e">
		/// Contain information about the state of the persistent object and the
		/// <see cref="Opf3.ObjectContext">ObjectContext</see> of the current operation.
		/// </param>
		void IObjectNotification.OnBeforePopulated(ObjectNotificationEventArgs e)
		{
			// Add code here, if required. Leave empty if the event is not required.
		}

		/// <summary>
		/// Invoked by the framework after the object is populated.
		/// </summary>
		/// <param name="e">
		/// Contain information about the state of the persistent object and the
		/// <see cref="Opf3.ObjectContext">ObjectContext</see> of the current operation.
		/// </param>
		void IObjectNotification.OnAfterPopulated(ObjectNotificationEventArgs e)
		{
			// Add code here, if required. Leave empty if the event is not required.
		}

		/// <summary>
		/// Invoked by the framework before the object is inserted.
		/// </summary>
		/// <param name="e">
		/// Contain information about the state of the persistent object and the
		/// <see cref="Opf3.ObjectContext">ObjectContext</see> of the current operation.
		/// </param>
		void IObjectNotification.OnBeforeInsert(ObjectNotificationEventArgs e)
		{
			// Add code here, if required. Leave empty if the event is not required.
		}

		/// <summary>
		/// Invoked by the framework after the object is inserted.
		/// </summary>
		/// <param name="e">
		/// Contain information about the state of the persistent object and the
		/// <see cref="Opf3.ObjectContext">ObjectContext</see> of the current operation.
		/// </param>
		void IObjectNotification.OnAfterInsert(ObjectNotificationEventArgs e)
		{
			// Add code here, if required. Leave empty if the event is not required.
		}

		/// <summary>
		/// Invoked by the framework before the object is updated.
		/// </summary>
		/// <param name="e">
		/// Contain information about the state of the persistent object and the
		/// <see cref="Opf3.ObjectContext">ObjectContext</see> of the current operation.
		/// </param>
		void IObjectNotification.OnBeforeUpdate(ObjectNotificationEventArgs e)
		{
			// Add code here, if required. Leave empty if the event is not required.
		}

		/// <summary>
		/// Invoked by the framework after the object is updated.
		/// </summary>
		/// <param name="e">
		/// Contain information about the state of the persistent object and the
		/// <see cref="Opf3.ObjectContext">ObjectContext</see> of the current operation.
		/// </param>
		void IObjectNotification.OnAfterUpdate(ObjectNotificationEventArgs e)
		{
			// Add code here, if required. Leave empty if the event is not required.
		}

		/// <summary>
		/// Invoked by the framework before the object is deleted.
		/// </summary>
		/// <param name="e">
		/// Contain information about the state of the persistent object and the
		/// <see cref="Opf3.ObjectContext">ObjectContext</see> of the current operation.
		/// </param>
		void IObjectNotification.OnBeforeDelete(ObjectNotificationEventArgs e)
		{
			// Add code here, if required. Leave empty if the event is not required.
		}

		/// <summary>
		/// Invoked by the framework after the object is deleted.
		/// </summary>
		/// <param name="e">
		/// Contain information about the state of the persistent object and the
		/// <see cref="Opf3.ObjectContext">ObjectContext</see> of the current operation.
		/// </param>
		void IObjectNotification.OnAfterDelete(ObjectNotificationEventArgs e)
		{
			// Add code here, if required. Leave empty if the event is not required.
		}

		/// <summary>
		/// Invoked by the framework after the object has been marked deleted.
		/// </summary>
		/// <param name="e">
		/// Contain information about the state of the persistent object and the
		/// <see cref="Opf3.ObjectContext">ObjectContext</see> of the current operation.
		/// </param>
		void IObjectNotification.OnBeforeMarkDeleted(ObjectNotificationEventArgs e)
		{
			// Add code here, if required. Leave empty if the event is not required.
		}

		/// <summary>
		/// Invoked by the framework after the object has been marked deleted.
		/// </summary>
		/// <param name="e">
		/// Contain information about the state of the persistent object and the
		/// <see cref="Opf3.ObjectContext">ObjectContext</see> of the current operation.
		/// </param>
		void IObjectNotification.OnAfterMarkDeleted(ObjectNotificationEventArgs e)
		{
			// Add code here, if required. Leave empty if the event is not required.
		}

		#endregion

		#region ISelfContainingObject Members

		private ObjectInfo _objectInfo = null;

		/// <summary>
		/// Returns the <see cref="Opf3.ObjectInfo">ObjectInfo</see> object that contains all
		/// information required to make the persistent object
		/// <see cref="Opf3.ObjectContext">independent from any ObjectContext</see>.
		/// </summary>
		/// <value>
		/// 	<see cref="Opf3.ObjectInfo">ObjectInfo</see> object that holds the status
		/// information of the persistent object.
		/// </value>
		ObjectInfo ISelfContainingObject.ObjectInfo
		{
			get { return _objectInfo; }
			set { _objectInfo = value; }
		}

		#endregion

		#region INotifyPropertyChanged Members

		/// <summary>
		/// Invokes the "PropertyChanged" event if a property has been changed and
		/// somebody subscribed the event.
		/// </summary>
		private void OnRowChanged(string propertyName)
		{
			if (PropertyChanged != null)
				PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
		}

		/// <summary>
		/// Event is fired if a property of the persistent changed.
		/// </summary>
		public event PropertyChangedEventHandler PropertyChanged;

		#endregion
	}
}
